var axios = require('axios');
const { ITEM_RENDER_EVT } = require('element-plus/es/components/virtual-list/src/defaults');

var data = JSON.stringify({
    message: '如何写日报',
});

var config = {
    method: 'post',
    url: 'https://v1.gptapi.cn',
    headers: {
        'Content-Type': 'application/json',
        'Content-Length': '',
    },
    data: data,
};

axios(config)
    .then(function (response) {
        console.log(JSON.stringify(response.data));
    })
    .catch(function (error) {
        console.log(error);
    });

function bubbleSort(arr) {
    // Loop through the array
    for (let i = 0; i < arr.length; i++) {
        // For each element in the array, loop through the array again
        for (let j = 0; j < arr.length; j++) {
            // If the current element is greater than the next element, swap them
            if (arr[j] > arr[j + 1]) {
                const temp = arr[j];
                arr[j] = arr[j + 1];
                arr[j + 1] = temp;
            }
        }
    }

    // Return the sorted array
    return arr;
}

res.data = [{ a: 1, b: 2, c: 3, d: 4, f: 5, key: 'xxxx', title: '菜单', children: [] }];
// 后端返回的数据
let menuList = res.data;
const dealTreeData = (menuList) => {
    const data = menuList.map((item) => ({
        key: item.key,
        title: item.title,
        children: item.children && item.children.length ? dealTreeData(item.children) : null,
    }));
    return data;
};
const menuTreeData = dealTreeData(menuList);
// 树的回显示
function getIds(arr, res = []) {
    arr.forEach((item) => {
        if (item.isChecked) {
            res.push(item.key);
        }
        return getIds(item.children, res);
    });
    return res;
}
const dealTreeId = getIds(menuList);
